<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The PhpToken class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="tokenizer.examples.html">« 范例</a></li>
      <li style="float: right;"><a href="phptoken.construct.html">PhpToken::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.tokenizer.html">Tokenizer</a></li>
    <li>The PhpToken class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.phptoken" class="reference">

 <h1 class="title">The PhpToken class</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 8)</p>


  <div class="section" id="phptoken.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    This class provides an alternative to <span class="function"><a href="function.token-get-all.html" class="function">token_get_all()</a></span>. While the function returns tokens
    either as a single-character string, or an array with a token ID, token text and line number,
    <span class="function"><a href="phptoken.tokenize.html" class="function">PhpToken::tokenize()</a></span> normalizes all tokens into PhpToken objects, which makes code operating
    on tokens more memory efficient and readable.
   </p>
  </div>


  <div class="section" id="phptoken.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">PhpToken</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.stringable.html" class="interfacename">Stringable</a></span> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname"><a href="class.phptoken.html#phptoken.props.id">$<var class="varname">id</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">string</span>
      <var class="varname"><a href="class.phptoken.html#phptoken.props.text">$<var class="varname">text</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname"><a href="class.phptoken.html#phptoken.props.line">$<var class="varname">line</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname"><a href="class.phptoken.html#phptoken.props.pos">$<var class="varname">pos</var></a></var>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="phptoken.construct.html" class="methodname">__construct</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$id</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$text</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$line</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$pos</code><span class="initializer"> = -1</span></span><br>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="phptoken.gettokenname.html" class="methodname">getTokenName</a></span>(): <span class="type"><span class="type">?</span><span class="type">string</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="phptoken.is.html" class="methodname">is</a></span>(<span class="methodparam"><span class="type"><span class="type">int</span>|<span class="type">string</span>|<span class="type">array</span></span> <code class="parameter">$kind</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="phptoken.isignorable.html" class="methodname">isIgnorable</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="phptoken.tostring.html" class="methodname">__toString</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="phptoken.tokenize.html" class="methodname">tokenize</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$code</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type">array</span></div>

   }</div>


  </div>

  <div class="section" id="phptoken.props">
   <h2 class="title">属性</h2>
   <dl>
    
     <dt id="phptoken.props.id"><var class="varname">id</var></dt>

     <dd>

      <p class="para">
       One of the T_* constants, or an ASCII codepoint representing a single-char token.
      </p>
     </dd>

    
    
     <dt id="phptoken.props.text"><var class="varname">text</var></dt>

     <dd>

      <p class="para">
       The textual content of the token.
      </p>
     </dd>

    
    
     <dt id="phptoken.props.line"><var class="varname">line</var></dt>

     <dd>

      <p class="para">
       The starting line number (1-based) of the token.
      </p>
     </dd>

    
    
     <dt id="phptoken.props.pos"><var class="varname">pos</var></dt>

     <dd>

      <p class="para">
       The starting position (0-based) in the tokenized string (the number of bytes).
      </p>
     </dd>

    
   </dl>

  </div>

 </div>

 






































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="phptoken.construct.html">PhpToken::__construct</a> — Returns a new PhpToken object</li><li><a href="phptoken.gettokenname.html">PhpToken::getTokenName</a> — Returns the name of the token.</li><li><a href="phptoken.is.html">PhpToken::is</a> — Tells whether the token is of given kind.</li><li><a href="phptoken.isignorable.html">PhpToken::isIgnorable</a> — Tells whether the token would be ignored by the PHP parser.</li><li><a href="phptoken.tostring.html">PhpToken::__toString</a> — Returns the textual content of the token.</li><li><a href="phptoken.tokenize.html">PhpToken::tokenize</a> — Splits given source into PHP tokens, represented by PhpToken objects.</li></ul>
</div>
</div></div></body></html>